﻿#include<stdio.h>
#include<graphics.h>//图像
#include<mmsystem.h>//多媒体
#include <windows.h>//还不知道是啥
#include<conio.h>
#include<stdlib.h>
#include<time.h>
#pragma comment(lib,"winmm.lib")
#define wide 1080//游戏界面的宽度
#define high 680//游戏界面的高度
#define wall_brick_size 40//砖块大小
#define ROW (wide/wall_brick_size)//行砖块数量
#define COL (high/wall_brick_size)//列砖块数量
#define brick_num 350
enum gameset
{
	SPACE,
	WALL,
	BRICK,
};
struct ROLE
{
	int x;
	int y;
	int role_width;
	int role_hight;
}player;
int map[COL][ROW];
IMAGE img[2];
IMAGE role_img[2];
//初始化游戏界面
void welcome()
{
	IMAGE background;
	loadimage(&background, "./游戏素材/背景.png", 1080, 680);
	putimage(0, 0, &background);
	mciSendString("open ./游戏素材/初始化背景音乐.mp3 alias BEGIN",0,0,0);
	mciSendString("play BEGIN repeat", 0, 0, 0);
	_getch();
	mciSendString("close BEGIN", 0, 0, 0);
	mciSendString("open ./游戏素材/游戏内背景音乐.mp3 alias BGM", 0, 0, 0);
	mciSendString("play BGM repeat", 0, 0, 0);
}
//游戏地图
void gamepaint()
{
	srand(GetTickCount());
	setbkcolor(RGB(80, 160, 1));
	cleardevice();
	loadimage(&img[0], "./游戏素材/墙.jpg", wall_brick_size, wall_brick_size);
	loadimage(&img[1], "./游戏素材/砖.jpg", wall_brick_size, wall_brick_size);
	loadimage(&role_img[0], "./游戏素材/人物y.jpg");
	loadimage(&role_img[1], "./游戏素材/人物.jpg");
	for (int i = 0;i < COL;i++)//列墙
	{
		map[i][0] = map[i][ROW - 1] = WALL;
	}
	for (int j = 0;j < ROW;j++)//行墙
	{
		map[0][j] = map[COL - 1][j] = WALL;
	}
	for (int i = 0;i < 60;i++)//打印内部墙体
	{
		for (int k = 0;k < 40;k++)
		{
			if (i % 2 == 0 && k % 2 == 0)
			{
				putimage(k * wall_brick_size, i * wall_brick_size, &img[0]);
			}
		}
	}
	for (int i = 0;i < brick_num;i++)//随机砖块
	{
		int c = rand() % COL;
		int r = rand() % ROW;
		if (map[c][r] == SPACE)
		{
			map[c][r] = BRICK;
		}
	}
	for (int i = 0;i < 60;i++)//打印边缘墙体
	{
		for (int k = 0;k < 40;k++)
		{
			switch (map[i][k])
			{
			case WALL:
				putimage(k * wall_brick_size, i * wall_brick_size, &img[0]);
				break;
			case BRICK:
				putimage(k * wall_brick_size, i * wall_brick_size, &img[1]);
				break;
			}
		}
	}
	//初始化人物
	player.x = rand() % ROW;
	player.y = rand() % COL;

	player.role_width = 30;
	player.role_hight = 30;
	putimage(player.x, player.y, player.role_width, player.role_hight, &role_img[1], 0, 0);
}
int main()
{
	initgraph(wide, high);
	welcome();
	gamepaint();
	while (1)
	{

	}
	closegraph();
	return 0;
}